const config = require('../../../config/config.local');
const amazonMws = require('amazon-mws')(config.AWSAccessKeyId, config.AWSSecretKey);
// const isProduction = process.env.NODE_ENV === 'production';

const d = {};

d.getFeedSubmissionList = function(seller_id, mws_auth_token, feedSubmissionIdList=null, feedTypeList=null, feedProcessingStatusList=null, maxCount=null) {
  let baseOption = {
    'Version': '2009-01-01',
    'Action': 'GetFeedSubmissionList',
    'SellerId': seller_id,
    'MWSAuthToken': mws_auth_token,
    // 'FeedSubmissionIdList.Id.1': '50286018306',
    // 'MaxCount': 1000,
  };
  if (feedSubmissionIdList){
    let keyPrefix = "FeedSubmissionIdList.Id";
    feedSubmissionIdList.forEach((item, index) => {
      baseOption[keyPrefix + "." + (index+1)] = item;
    });
  }
  if (feedTypeList) {
    let keyPrefix = "FeedTypeList.Type";
    feedTypeList.forEach((item, index) => {
      baseOption[keyPrefix + "." + (index+1)] = item
    });
  }
  if (feedProcessingStatusList) {
    let keyPrefix = "FeedProcessingStatusList.Status";
    feedProcessingStatusList.forEach((item, index) => {
      baseOption[keyPrefix + "." + (index+1)] = item
    });
  }
  if (maxCount){
    baseOption["MaxCount"] = maxCount;
  }
  return amazonMws.feeds.search(baseOption);
};

module.exports = d;